<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>点击列表输出索引</title>
</head>
<style>
  li {
    cursor: pointer;
  }
</style>
<body>
  <ul>
    <li>序号1</li>
    <li>序号2</li>
    <li>序号3</li>
    <li>序号4</li>
    <li>序号5</li>
    <li>序号6</li>
    <li>序号7</li>
    <li>序号8</li>
    <li>序号9</li>
    <li>序号10</li>
  </ul>
  <script>
    var list = document.getElementsByTagName('li');
    var len = list.length;
    for (var i = 0; i < len; i++) {
      (function (n) {
        list[n].onclick = function () {
          alert(n + 1);
        }
      })(i)
    }
  </script>
</body>

</html>